
<template>
  <div class="home">
    <h6>正在热播</h6>
    <div class="wrapper" ref="wrapper">
      <ul class="content" ref="content">
        <li
          v-for="(item,index) in movieList"
          :key="item.id"
          @click="selectHomeData(index)" >
          <div class="num">
            <img :src="item.img" alt="" />
            <span>观众评分：{{item.sc}}</span>
          </div>
          <div class="text">
          <span>{{item.nm}}</span>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import BScroll from "better-scroll";

export default {
  data() {
    return {
      movieList: [],
    };
  },
  created() {
    this.getHomeData();
  },
  methods: {
    getHomeData() {
      axios
        .get("/api/hotingList.json")
        .then((res) => {
          console.log(res.data);
          this.movieList = res.data.movieList
          this.betterScrollHorizontal(this.movieList.length, 115);
        })
        .catch((err) => {
          console.error(err);
        });
    },
     betterScrollHorizontal(num, itemWidth) {
      let width = num * itemWidth;
      this.$refs.content.style.width = width + "px";
      this.$nextTick(() => {
        this.scroll = new BScroll(this.$refs.wrapper, {
          click: true,
          startX: 0,
          scrollX: true, //水平横向
          scrollY: false,
        });
      });
    },
      selectHomeData(id){
        console.log(id);
                
      this.$router.push({
        path: `/top/${id}`,
      });
      }
  },

};
</script>

<style scoped>
.home {
  margin: 0 auto;
  width: 90%;
}
.home > h6 {
  text-align: left;
  margin: 10px 5px 0px 10px;

}
.wrapper {
  width: 100%;
  overflow: hidden;
}
ul.content {
  padding-left: 0;
}
ul.content > li {
  list-style: none;
  width: 115px;
  display: inline-block;
  text-align: center;
  vertical-align: top;
}
.num {
  position: relative;
  display: inline-block;
}
.num > img {
  width: 100px;
  height: 135px;
}
.num > span {
      font-size: 12px;
       color: white;
    background-color: rgb(221,121,7,0.70);
    position: absolute;
    /* 绝对定位 */
    bottom: 4.5px;
    z-index: 100px;
    /* 优先级 */
    display: block;
    width: 100px;
}
.text > span {
  font-weight: bold;
     display: block;
     padding-left: 10px;
   margin: 0 auto;
   font-size: 17px;
   width: 80%;
   text-align: center;
  /*  一定要设置宽度，或者元素内含的百分比 */
  overflow: hidden; /*溢出的部分隐藏*/
  white-space: nowrap; /*文本不换行*/
  text-overflow: ellipsis;
}
/* .text>p {
   display: block;
   width: 90%;
   margin: 0 auto;
   font-size: 12px;
} */
</style>
